<template>
<el-dialog class="add-dialog" :append-to-body="true" :close-on-click-modal="false" :title="addForm.title" :visible.sync="addForm.show" width="500px">
    <el-form ref="ruleForm" :model="addForm.form" :rules="rules" label-width="100px">
        <el-form-item label="键" prop="keyy">
            <el-input clearable placeholder="请输入键" v-model="addForm.form.keyy"></el-input>
        </el-form-item>
        <el-form-item label="值" prop="valuee">
            <el-input clearable placeholder="请输入值" v-model="addForm.form.valuee"></el-input>
        </el-form-item>
        <el-form-item label="表名" prop="tableName">
            <el-input clearable placeholder="请输入表名" v-model="addForm.form.tableName"></el-input>
        </el-form-item>
        <el-form-item label="字段" prop="fieldName">
            <el-input clearable placeholder="请输入字段" v-model="addForm.form.fieldName"></el-input>
        </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="addForm.show=false">取 消</el-button>
      <el-button type="primary" v-preventReClick="2000" @click="handleSave">确 定</el-button>
    </span>
</el-dialog>
</template>

<script>
export default {
    name: 'AddDialog',
    props: {
        addForm: {
            type: Object,
            required: true
        }
    },
    data () {
        return {
            rules: {
                keyy: [{
                    required: true,
                    message: '请输入键',
                    trigger: 'blur'
                }
                ],
                valuee: [{
                    required: true,
                    message: '请输入值',
                    trigger: 'blur'
                }],
                tableName: [{
                    required: true,
                    message: '请输入表名',
                    trigger: 'blur'
                }],
                fieldName: [{
                    required: true,
                    message: '请输入字段',
                    trigger: 'blur'
                }]
            }
        }
    },
    methods: {
        handleSave () {
            this.$refs['ruleForm'].validate((valid) => {
                if (valid) {
                    this.$emit('save')
                } else {
                    return false
                }
            })
        }
    }
}
</script>
